// import Vue from 'vus

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: JSON.parse(localStorage.getItem("userInfo")),
    touristInfo: JSON.parse(localStorage.getItem('touristInfo')),
    headFlag: false
  },
  mutations: {
    // set
    SET_TOKEN: (state, token) => {
      state.token = token
      localStorage.setItem("token", token)
    },
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
      localStorage.setItem("userInfo", JSON.stringify(userInfo))
    },
    REMOVE_INFO: (state) => {
      state.token = ''
      state.userInfo = {}
      localStorage.setItem("token", '')
      localStorage.setItem("userInfo", JSON.stringify(''))
    },
    SET_TOURISTINFO: (state, touristInfo)=>{
      state.touristInfo = touristInfo
      localStorage.setItem("touristInfo", JSON.stringify(touristInfo))
    },
    REMOVE_TOURISTINFO: (state) => {
      state.touristInfo = {},
      localStorage.setItem("touristInfo", JSON.stringify(''))
    },
    T_HEADFLAG: (state) => {
      state.headFlag = true
    },
    F_HEADFLAG: (state) => {
      state.headFlag = false
    }
  },
  getters: {
    // get
    getUser: state => {
      return state.userInfo
    },
    getTourist: state => {
      return state.touristInfo
    },
    getHeadFlag: state => {
      return state.headFlag
    }
  },
  actions: {
  },
  modules: {
  }
})
